package utn.frd.form;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import utn.frd.domain.Gol;

public class FormRiquelme extends HttpServlet {
	
	private static final long serialVersionUID = 2L;
    
	private HashMap<String,Gol> goles = new HashMap<String,Gol>(); 
	
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    	try{
	    	Gol g = new Gol();
			g.setNombre( request.getParameter("name") );
			g.setPartido( request.getParameter("partido") );
			g.setEstadio( request.getParameter("estadio") );
			if( request.getParameter("minuto")!=null )
				g.setMinuto( Integer.parseInt(request.getParameter("minuto")) );
				
			goles.put( request.getParameter("name"), g );	
			
    	}catch (Exception e) {
			request.setAttribute("error", e.getMessage());
		}
		
		request.setAttribute("goles", new ArrayList<Gol>( goles.values() ));
    	
    	request.getRequestDispatcher("riquelme.jsp").forward(request, response);
	}
}
